<?xml version="1.0" encoding="utf-8" ?> 
<sqlMap namespace="FlashAD"
	xmlns="http://ibatis.apache.org/mapping" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<alias>
		<typeAlias alias="FlashAD" type="Domain.FlashAD" />
	</alias>

	<resultMaps>
		<resultMap id="FullResultMap" class="FlashAD">
			<result property="id" column="id" dbType="Int"/>
			<result property="description" column="description" dbType="NVarChar"/>
			<result property="imagePath" column="imagePath" dbType="NVarChar"/>
			<result property="linkUrl" column="linkUrl" dbType="NVarChar"/>
			<result property="adOrder" column="adOrder" dbType="Int"/>
			<result property="addDate" column="addDate" dbType="SmallDateTime"/>
		</resultMap>
	</resultMaps>
	
	<statements>

		<select id="GetCount" resultClass="System.Int32">
			SELECT count(*) FROM [dbo].[flashAD]
		</select>
		
		<select id="GetCountByCondition" parameterClass="Hashtable" resultClass="System.Int32" extends="GetCount">
			WHERE $condition$
		</select>
		
		<select id="FindAll" resultClass="FlashAD">
			SELECT * 
			FROM [dbo].[flashAD]
		</select>
		
		<select id="GetModel" parameterClass="FlashAD" resultClass="FlashAD" extends="FindAll">
			WHERE
				([flashAD].[id] = #id,dbType=Int#)
		</select>

		<insert id="Insert" parameterClass="FlashAD">
			INSERT INTO [dbo].[flashAD] (
				[description] , 
				[imagePath] , 
				[linkUrl] , 
				[adOrder] , 
				[addDate]
			) VALUES (
				 #description,dbType=NVarChar# , 
				 #imagePath,dbType=NVarChar# , 
				 #linkUrl,dbType=NVarChar# , 
				 #adOrder,dbType=Int# , 
				 #addDate,dbType=SmallDateTime#
			)
		</insert>

		<update id="Update" parameterClass="FlashAD">
			UPDATE [dbo].[flashAD] SET
				 [description] = #description,dbType=NVarChar#
				, [imagePath] = #imagePath,dbType=NVarChar#
				, [linkUrl] = #linkUrl,dbType=NVarChar#
				, [adOrder] = #adOrder,dbType=Int#
				, [addDate] = #addDate,dbType=SmallDateTime#
			WHERE
				([id] = #id,dbType=Int#)
		</update>

		<delete id="Delete" parameterClass="FlashAD">
			DELETE FROM [dbo].[flashAD]
			WHERE
				([id] = #id,dbType=Int#)
		</delete>

		<select id="GetModelsByCondition" parameterClass="Hashtable" resultClass="FlashAD">
			SELECT $columnNames$ FROM [dbo].[flashAD] where $condition$
		</select>
		
		<select id="GetModelsByConditionByPager" parameterClass="Hashtable" resultClass="FlashAD">
      declare @indextable table(rno int identity(1,1),nid int)
      insert into @indextable(nid) select [id] from [dbo].[flashAD]
      where $condition$ order by $orderBy$

      select $columnNames$ from
      [dbo].[flashAD] ,@indextable t
      <![CDATA[
			where t.nid= [flashAD].id and t.rno>#startNo# and t.rno<=#endNo# 
      order by t.rno asc
			]]>
		</select>
		
	</statements>
</sqlMap>
